// 获取验证码
var reg = /^(\+?44|0)7\d{9}$/;
$('.get_code_btn').click(function () {
    $tel =  $('.tel').val();
    if ($tel){
        if (!checkTel($tel)) return false;
    }
    if ('' == $tel){
        layer.msg('请输入手机号',{
            skin:'winning-class',
            time:3000
        });
    }else {
        $.ajax({
            type: "post",
            url: "/userweb/login/codeGet",
            cache: false,
            data: {
                account: $tel,
                type:'unregistered'
            },
            dataType: "json",
            success: function (data) {
                layer.msg(data.msg,{
                    skin:'winning-class',
                    time:3000
                });
                if(200 == data.status){
                    function invokeSettime(obj) {
                        var countdown = 60;
                        settime(obj);
                        function settime(obj) {
                            var text = '<div class="my_title_zh">获取验证码</div>' +
                                '<div class="my_title_en">Get the verify</div>';
                            if (countdown == 0) {
                                $(obj).attr("disabled",false);
                                $(obj).html(text);
                                countdown = 60;
                                return;
                            } else {
                                var html = '<div class="code_time">' +
                                    '<div class="code_time_s">'+ countdown +'S</div>' +
                                    '<div class="code_time_text">' +
                                    '<div>重新发送</div>' +
                                    '<div>Resend</div>' +
                                    '</div>' +
                                    '</div>';
                                $(obj).attr("disabled",true);
                                $(obj).html(html);
                                countdown--;
                            }
                            setTimeout(function() {
                                settime(obj);
                            },1000);
                        }

                    }
                    new invokeSettime('.get_code_btn');
                }
            }
        });
    }
})
// 重置密码
$('.my_submit_btn').click(function () {
    var code = $('.input_code').val();
    var password =  $('.pwd').val();
    var tel =  $('.tel').val();
    if (tel){
        if (!checkTel(tel)) return false;
    }
    if ('' == tel){
        layer.msg('请输入手机号',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else if ('' == password){
        layer.msg('密码不能为空',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else if ('' == code){
        layer.msg('请输入验证码',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else {
        $.ajax({
            type: "post",
            url: "/userweb/login/pwdRest",
            cache: false,
            data: {account: tel, password: password, code: code},
            dataType: "json",
            success: function (data) {
                if (200 == data.status) {
                    layer.msg('修改成功',{
                        skin:'winning-class',
                        time:3000
                    });
                    location.href = "/userweb/index/login";
                }
            }
        });
    }
});